<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-04 16:53:56
 * @LastEditTime: 2023-07-01 09:26:11
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\BaseData;

use App\Http\Services\Service;

use App\Repositories\TradeRepository;
use Illuminate\Support\Facades\DB;

/**
 * @property TradeRepository $repository
 */
class TradeService extends Service
    {

    public function __construct(TradeRepository $repository)
        {
        $this->repository = $repository;
        }

    public function list()
        {
        $data = $this->repository->condition(request())->getGrid();
        return $data;
        }
    protected function save($request)
        {
        // DB::enableQueryLog();
        // dd(DB::getQueryLog());
        $data = $request->toArray();
        if (isEmpty($data['sort'])) {
            $data['sort'] = 0;
            }
        $gdata = $this->repository->autosave($data);
        if ($gdata->sort == 0) {
            $gdata->sort = $gdata->id;
            $gdata->save();
            }
        return $gdata;
        }
    protected function delete()
        {
        return $this->repository->autodelete($this->getRequestIds());
        }

    }